/**
 * Created by mooshroom on 2014/11/28.
 */
var login =function(){
    return{
        init:function(){
            login.togglePanel();//面板切换
            login.loginSubmit();//登录提交
            login.registerSubmit();//注册提交

        },
        togglePanel:function(){
            $("#registerPanel").hide();
            $(".toggle-panel-btn").click(function(){
                $(".toggle-panel").toggle();
                return false
            });
        },
        loginSubmit:function(){

            $("#loginBtn").click(function(){
                $.ajax({
                    type: "POST",
                    url: "index.php?s=Home/User/checkUserPassword",
                    data: $("#UserLogin").serialize(),//序列化form表单,
                    dataType: "html",
                    success: function (data) {
                        var obj = JSON.parse(data);
                        if(obj.code==200)
                        {
                            window.location.href = "index.php?s=Home/Pages/doc"
                        }
                        else
                        {
                            alert("登录失败~！");
                        }

                    },
                    error: function (a, b, c) {
                        alert(a);
                    }
                });
                return false;
            });

        },
        registerSubmit:function(){
            $("#registerBtn").click(function(){
                $.ajax({
                    type:"POST",
                    url:"index.php?s=Home/Pages/userRegist",
                    data:$("#UserRegister").serialize(),
                    dataType: "html",
                    success: function(data)
                    {
                        var obj = JSON.parse(data);
                        if(obj.code==200)
                        {
                            alert("注册成功！");//注册成功的提示
                        }
                        else
                        {
                            alert("注册失败！");//注册失败的提示
                        }
                    },
                    error:function(a,b,c)
                    {
                        alert(a);
                    }
                });
                return false;
            });
        }

    }
}();